package com.infore.dataReceiving.netty.client;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import io.netty.channel.ChannelInitializer;  
import io.netty.channel.ChannelPipeline;  
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.LineBasedFrameDecoder;
import io.netty.handler.codec.string.StringDecoder;  
import io.netty.handler.codec.string.StringEncoder;

@Component
@Qualifier("clientChannelInitializer")
public class ClientChannelInitializer extends ChannelInitializer<SocketChannel> {  
	
	@Autowired
	StringDecoder stringDecoder;

	@Autowired
	StringEncoder stringEncoder;

	@Autowired
	ClientHandler clientHandler;

    
    @Override  
    protected void initChannel(SocketChannel ch) throws Exception {  
    	ChannelPipeline pipeline = ch.pipeline();
    	pipeline.addLast("lineBasedFrameDecoder", new LineBasedFrameDecoder(1024));//new DelimiterBasedFrameDecoder(1024,delimiter)
        pipeline.addLast("decoder", stringDecoder);
        pipeline.addLast("encoder", stringEncoder);
        pipeline.addLast("handler", clientHandler);
    }  
}